home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / backend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.1 KB  |  72 lines

  1. /*
  2.                                 B A C K E N D . C
  3.  
  4.         version
  5.         offset of the string constant-area  (INT32)
  6.         offset of the variable area         (INT32)
  7.         offset of the strings area          (INT32)
  8.         offset of the first instruction     (INT32)
  9.  
  10.         code                                (first byte is first instruction)
  11.         ascii-z string constant area
  12.         variables
  13.         filenames
  14. */
  15.  
  16. #include "iccomp.h"
  17.  
  18. static INT8
  19.     opexit = op_exit,
  20.     opcall = op_call;
  21.  
  22. void backend()
  23. {
  24.     register unsigned
  25.         index;
  26.     BIN_HEADER_
  27.         hdr;
  28.  
  29.     strcpy(string, "main");
  30.     if ((index = looksym(&funtab)) == funtab.n_defined)
  31.     {
  32.         semantic("function 'main()' not defined");
  33.         exit(1);
  34.     }
  35.  
  36.     hdr.offset[3] = ftell(s_bin);           /* offset of first instruction */
  37.  
  38.     hidden_functions();                     /* patchup generated hidden */
  39.                                             /* function calls */
  40.  
  41.     fseek(s_bin, 0, SEEK_END);              /* upwind to EOF again */
  42.  
  43.     outbin(&opcall, sizeof(INT8));          /* call main() at its offset */
  44.     outbin(&funtab.symbol[index].var.vu.i->count, sizeof(INT16));
  45.  
  46.     outbin(&opexit, sizeof(INT8));          /* generate op_ret at the end */
  47.  
  48.     strcpy(hdr.version, version);           /* set the version */
  49.  
  50.     hdr.offset[0] = ftell(s_bin);           /* here the strings start */
  51.  
  52.                                             /* generate the strings */
  53.     for (index = 0; index < n_strings; index++)
  54.         fprintf(s_bin, "%s%c", stringtab[index].string, 0);
  55.  
  56.     hdr.offset[1] = ftell(s_bin);           /* here the vars start */
  57.  
  58.     for (index = 0; index < global.n_defined; index++)
  59.     {
  60.         global.symbol[index].var.type &= ~e_var; /* remove 'var' indicator */
  61.         fwrite(&global.symbol[index].var, 1, sizeof(VAR_), s_bin);
  62.     }
  63.  
  64.     hdr.offset[2] = ftell(s_bin);           /* here the filenames start */
  65.     fputs(filenames, s_bin);
  66.  
  67.     rewind(s_bin);
  68.                                             /* write the offset info */
  69.     fwrite(&hdr, sizeof(BIN_HEADER_), 1, s_bin);
  70.  
  71.  
  72. }